feat!: Use a radix trie for route matching - #628
Conversation
|
| Project | cot |
| Branch | elijah/router-trie |
| Testbed | github-ubuntu-latest |
Click to view all benchmark results
| Benchmark | Latency | Benchmark Result milliseconds (ms) (Result Δ%) | Upper Boundary milliseconds (ms) (Limit %) |
|---|---|---|---|
| empty_router/empty_router | 📈 view plot 🚷 view threshold | 14.44 ms(+52.66%)Baseline: 9.46 ms | 17.95 ms (80.44%) |
| json_api/json_api | 📈 view plot 🚷 view threshold | 1.14 ms(+10.42%)Baseline: 1.03 ms | 1.36 ms (83.49%) |
| nested_routers/nested_routers | 📈 view plot 🚷 view threshold | 1.09 ms(+12.89%)Baseline: 0.96 ms | 1.25 ms (86.83%) |
| single_root_route/single_root_route | 📈 view plot 🚷 view threshold | 1.02 ms(+10.40%)Baseline: 0.93 ms | 1.22 ms (84.20%) |
| single_root_route_burst/single_root_route_burst | 📈 view plot 🚷 view threshold | 17.43 ms(+3.61%)Baseline: 16.82 ms | 21.43 ms (81.30%) |
|
Should be rebased on and merged after #586 |
| fn register_apps(&self, apps: &mut AppBuilder, _context: &RegisterAppsContext) { | ||
| apps.register_with_views(App1, ""); | ||
| apps.register_with_views(App2, ""); | ||
| apps.register_with_views(App2, "/foo"); |
There was a problem hiding this comment.
Do we have any way of registering multiple routers at the same URL? This is an important feature - people might want to merge different routers at the same base URL.
If matchit doesn't let us do that because it detects a conflict, we should merge the routers. I'm not sure if we should have separate methods to do that explicitly, or keep the implicit behavior - I'll let you decide.
There was a problem hiding this comment.
Ended up going towards the implicit route. When two routers share the same path, we implicitly merge them into one right before we build the route lookup table and trie
| /// Panics when a url string could not be parsed into a [`Route`] | ||
| #[must_use] | ||
| pub fn with_urls<T: Into<Vec<Route>>>(urls: T) -> Self { | ||
| match Self::try_with_urls(urls) { |
Codecov Report❌ Patch coverage is
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Description
The current router implementation uses a
Vecto store routers, which has some real limitations. For example, using a vec meant route conflict detection was cumbersome and hacky to get right. Using a Radix trie is the right data structure for this problem. This PR delegates the core Trie logic to the matchit crate. We still keep our business logic in a light wrapper over the Matchit Router.Breaking Changes
Type of change